#include <iostream>
#include <queue>
#include <stack>
using namespace std;

int main(){
    queue<int> a;
    stack<int> b;
    int x;
    while(1){
        cin>>x;
        if(x>=10&&x<=99){
            a.push(x);
        }else if(x==-1){
            a.pop();
        }else if(x==-2){
            while(!a.empty()){
                cout<<a.front()<<" ";
                b.push(a.front());
                a.pop();
            }
            while(!b.empty()){
                a.push(b.top());
                b.pop();
            }
            cout<<endl;
        }else if(x==-3){
            break;
        }
    }
    
}